﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using devtm.Collections;
using devtm.CommonInteractive.Config;

namespace CommonInteractive.Config
{

    /// <summary>
    /// TableCollection est une collection qui permet de manager dynamiquement différentes vues de la meme collection.
    /// </summary>
    public class AssemblyRepository :TableCollection<Assembly, string>
    {

        public AssemblyRepository()
            : base(c => c.Location)
        {

            // creation d'une liste indexée sur la propriete FullName
            IndexNameAssembly = this.GetIndex(c => c.FullName);            

        }


        public TableCollection<Assembly, string> IndexNameAssembly {get; set;}


        public IEnumerable<Assembly> SelectOnlyWithReference(AssemblyName filter, bool strict)
        {
            foreach (var item in this)
                foreach (AssemblyName item1 in item.GetReferencedAssemblies())
                    if ((strict && item1.FullName == filter.FullName) || (!strict && item1.Name == filter.Name))
                    {
                        yield return item;
                        break;
                    }

        }


    }
}
